////////////////////////////////////////////////
// File: AdvertisementService.java
// Description: Enter summary here after generation.
// Date: 2016-09-23 09:09:33
// Web: http://www.elanzhou.com/
////////////////////////////////////////////////
package com.mvc.service;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import com.mvc.dao.EntityDao;
import com.mvc.entity.Advertisement;
import com.mvc.entity.News;
import com.pub.Page;

@Service
public class HomeService {
	@Autowired
	private EntityDao entityDao;

	// protected final transient Log logger =
	// LogFactory.getLog(HomeService.class);

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getSyscateList(String Fname) {
		String hql = "select a from Syscate a where a.Fname='" + Fname
				+ "' and a.Catename<>'#' order by a.ID asc";

		List<Object> list = entityDao.query(hql);
		return list;
	}
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getSyscateListNum(String Fname,int sl) {
		String hql = "select a from Syscate a where a.Fname='" + Fname
				+ "' and a.Catename<>'#' order by a.ID asc";

		List<Object> list = entityDao.query(hql,sl);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getFcateList() {
		String hql = "select a from Syscate a where a.Catename='#' order by a.ID asc";
		List<Object> list = entityDao.query(hql);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getFcateListNum(int sl) {
		String hql = "select a from Syscate a where a.Catename='#' order by a.ID asc";
		List<Object> list = entityDao.query(hql,sl);
		return list;
	}

	
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getAdlist(String Adtype, int sl) {
		String hql = "select a from Advertisement a where a.Adtype='" + Adtype
				+ "' order by a.ID desc";
		// System.out.println(hql);

		List<Object> list = entityDao.query(hql, sl);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getGoodsList(String Goodstype, String Ispic, int sl) {

		String hql = "select a from Goods a  order by a.ID desc";
		if (Goodstype.equals("全部")) {
			hql = "select a from Goods a  and a.Status='已审核' order by a.ID desc";
			if (Ispic.equals("是")) {
				hql = "select a from Goods a where (GoodsPic<>'/upfile/goods.jpg') and a.Status='已审核' order by a.ID desc";
			}
			if (Ispic.equals("否")) {
				hql = "select a from Goods a where  (GoodsPic='/upfile/goods.jpg') and a.Status='已审核' order by a.ID desc";
			}
		} else {
			hql = "select a from Goods a where a.Goodstype='" + Goodstype
					+ "' and a.Status='已审核' order by a.ID desc";
			if (Ispic.equals("是")) {
				hql = "select a from Goods a where a.Goodstype='"
						+ Goodstype
						+ "' and (GoodsPic<>'/upfile/goods.jpg') and a.Status='已审核' order by a.ID desc";
			}
			if (Ispic.equals("否")) {
				hql = "select a from Goods a where a.Goodstype='"
						+ Goodstype
						+ "'  and (GoodsPic='/upfile/goods.jpg') and a.Status='已审核' order by a.ID desc";
			}
		}
		List<Object> list = entityDao.query(hql, sl);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getGoodsListBySyscate(String Goodstype, String Catename, int sl) {

		String hql = "select a from Goods a where a.Goodstype='" + Goodstype
					+ "' and a.Catename='"+Catename+"'and a.Status='已审核' order by a.ID desc";			
		List<Object> list = entityDao.query(hql, sl);
		return list;
	}

	
	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getNewsList(String Syschannel, String Newstype, int sl) {
		String hql = "";
		if (Syschannel.equals("全部")) {
			hql = "select a from News a where Newstype='" + Newstype
					+ "' order by a.ID desc";
			if (Newstype.equals("全部")) {
				hql = "select a from News a order by a.ID desc";
			}
		} else {
			hql = "select a from News a where a.Syschannel='" + Syschannel
					+ "' and Newstype='" + Newstype + "' order by a.ID desc";
			if (Newstype.equals("全部")) {
				hql = "select a from News a where a.Syschannel='" + Syschannel
						+ "'  order by a.ID desc";
			}
		}
		// System.out.print(hql);
		List<Object> list = entityDao.query(hql, sl);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getNewsListBySyscate(String SysCateName,
			 int sl) {
		String hql = "select a from News a where a.Catename='" + SysCateName
					+ "' order by a.ID desc";
		List<Object> list = entityDao.query(hql, sl);
		
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getPicNewsList(String Syschannel, String Newstype,
			int sl) {
		String hql = "";
		if (Syschannel.equals("全部")) {
			hql = "select a from News a where Newstype='" + Newstype
					+ "' and a.Newspic<>'/upfile/news.jpg' order by a.ID desc";
			if (Newstype.equals("全部")) {
				hql = "select a from News a where a.Newspic<>'/upfile/news.jpg'  order by a.ID desc";
			}
		} else {
			hql = "select a from News a where a.Syschannel='" + Syschannel
					+ "' and Newstype='" + Newstype
					+ "' and a.Newspic<>'/upfile/news.jpg'  order by a.ID desc";
			if (Newstype.equals("全部")) {
				hql = "select a from News a where a.Syschannel='"
						+ Syschannel
						+ "'  and a.Newspic<>'/upfile/news.jpg'   order by a.ID desc";
			}
		}
		// System.out.print(hql);
		List<Object> list = entityDao.query(hql, sl);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getBusinessList(int sl) {
		String hql = "select a from Business  a order by a.Star desc";
		List<Object> list = entityDao.query(hql, sl);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getMarketList(int sl) {
		String hql = "select a from Market  a order by a.ID desc";
		List<Object> list = entityDao.query(hql, sl);
		return list;
	}

	@Transactional(propagation = Propagation.NOT_SUPPORTED)
	public List<Object> getBusinessListBystar(int sl) {
		String hql = "select a from Business  a order by a.Star desc,a.ID desc";
		List<Object> list = entityDao.query(hql, sl);
		return list;
	}
}
